import message from '@/ui/message';
import loader from '@/ui/loader';
import runtimeManager from '@/ui/runtimeManager';

class MessageManager{
    constructor(){
        this.message=message;
    }
    init(){
        this.message.receive('loadResource',(msg)=>{
            // console.log("渲染线程接收消息1:",msg)
            const {appId,pagePath,platform,currProjectPath}=msg
            loader.loadResources({appId,pagePath,platform,currProjectPath});
        })
        this.message.receive('setInitialData',(msg)=>{
            // console.log("渲染线程接收消息2:",msg)
            const {pagePath,bridgeId}=msg
            loader.setInitialData(msg.initialData);
            runtimeManager.firstRender({
                pagePath,
                bridgeId
            });
        })
        this.message.receive('updateModule',(msg)=>{
            const {id,data}=msg
            runtimeManager.updateModule({
                id,
                data
            });
        })
        this.message.receive('showToast',(msg)=>{
            window.wxComponetsAPI({
                ...msg
            })
        })

    }

}

export default new MessageManager();